home *** CD-ROM | disk | FTP | other *** search
/ NetObjects Fusion 7 / Fusion7.iso / NetObjects Fusion / data1.cab / Language_Resource_-_English / Components / TimeBasedApplet / TimeBasedComp.jar / TimeBasedComp / TimeBasedComp.class (.txt)
Encoding:
Java Class File  |  2000-10-30  |  8.7 KB  |  331 lines

  1. package TimeBasedComp;
  2.  
  3. import com.netobjects.nfc.api.CStringArray;
  4. import com.netobjects.nfc.api.ComponentApp;
  5. import com.netobjects.nfc.api.DAssetManager;
  6. import com.netobjects.nfc.api.DDrawJava;
  7. import com.netobjects.nfc.api.DImage;
  8. import com.netobjects.nfc.api.DLayout;
  9. import com.netobjects.nfc.api.DRect;
  10. import com.netobjects.nfc.api.DSite;
  11. import com.netobjects.nfc.api.DSize;
  12. import com.netobjects.nfc.api.DStyle;
  13. import com.netobjects.nfc.api.IDInspector;
  14. import java.util.ResourceBundle;
  15.  
  16. public class TimeBasedComp extends ComponentApp {
  17.    int maxWidth;
  18.    int maxHeight;
  19.    int numImages;
  20.    static final int MaxImages = 24;
  21.    DDrawJava theJavaApplet;
  22.    int[] imageNames;
  23.    int[] imageURLs;
  24.    String[] linkTargets;
  25.    int[] imageStarts;
  26.    DAssetManager assetMan;
  27.  
  28.    public void migrationPatch() {
  29.       if (this.imageNames == null) {
  30.          this.imageNames = new int[24];
  31.       }
  32.  
  33.       if (this.imageURLs == null) {
  34.          this.imageURLs = new int[24];
  35.       }
  36.  
  37.       if (this.linkTargets == null) {
  38.          this.linkTargets = new String[24];
  39.       }
  40.  
  41.    }
  42.  
  43.    public void onCopy() {
  44.       int[] imageNamesOld = this.imageNames;
  45.       int[] imageURLsOld = this.imageURLs;
  46.       this.imageNames = new int[24];
  47.       this.imageURLs = new int[24];
  48.  
  49.       for(int cnt = 0; cnt < this.numImages; ++cnt) {
  50.          this.imageNames[cnt] = imageNamesOld[cnt];
  51.          this.imageURLs[cnt] = imageURLsOld[cnt];
  52.          if (this.imageNames[cnt] != 0) {
  53.             this.assetMan.CopyAsset(this.imageNames[cnt]);
  54.          }
  55.  
  56.          if (this.imageURLs[cnt] != 0) {
  57.             this.assetMan.CopyAsset(this.imageURLs[cnt]);
  58.          }
  59.       }
  60.  
  61.    }
  62.  
  63.    public void onDrop(DLayout layout, DRect r, int fDrop) {
  64.       if (fDrop == 1) {
  65.          this.maxWidth = 0;
  66.          this.maxHeight = 0;
  67.          this.numImages = 3;
  68.          this.imageURLs = new int[24];
  69.          this.linkTargets = new String[24];
  70.          this.imageNames = new int[24];
  71.          this.imageStarts = new int[24];
  72.  
  73.          for(int i = 0; i < 24; this.imageStarts[i] = i++) {
  74.             this.imageNames[i] = 0;
  75.             this.imageURLs[i] = 0;
  76.          }
  77.  
  78.          this.theJavaApplet = new DDrawJava();
  79.          this.theJavaApplet.setImageFile(this.theJavaApplet.getCodeBase() + "banner.gif");
  80.          this.theJavaApplet.setAppletFileName(this.theJavaApplet.getCodeBase() + "TimeBased.class");
  81.          this.theJavaApplet.setStretch(2);
  82.          this.theJavaApplet.setAltTag(ResourceBundle.getBundle("TimeBasedComp").getString("Component_Name"));
  83.          int xPos = r.getLeft();
  84.          int yPos = r.getTop();
  85.          this.theJavaApplet.AddParam("Number of Images", "String", "3");
  86.          this.imageNames[0] = this.assetMan.AddAsset(this.theJavaApplet.getCodeBase() + "banner.gif", "Image", "");
  87.          this.imageNames[1] = this.assetMan.AddAsset(this.theJavaApplet.getCodeBase() + "banner2.gif", "Image", "");
  88.          this.imageNames[2] = this.assetMan.AddAsset(this.theJavaApplet.getCodeBase() + "banner3.gif", "Image", "");
  89.          DImage imageSizer = new DImage();
  90.          imageSizer.setImageFile(this.theJavaApplet.getCodeBase() + "banner.gif");
  91.          DSize currentImageSize = imageSizer.getSize();
  92.          if (currentImageSize.getHeight() > this.maxHeight) {
  93.             this.maxHeight = currentImageSize.getHeight();
  94.             if (currentImageSize.getWidth() > this.maxWidth) {
  95.                this.maxWidth = currentImageSize.getWidth();
  96.             }
  97.  
  98.             this.theJavaApplet.SetPositionRect(xPos, yPos, xPos + this.maxWidth, yPos + this.maxHeight);
  99.          } else if (currentImageSize.getWidth() > this.maxWidth) {
  100.             this.maxWidth = currentImageSize.getWidth();
  101.             this.theJavaApplet.SetPositionRect(xPos, yPos, xPos + this.maxWidth, yPos + this.maxHeight);
  102.          }
  103.  
  104.          layout.AddObject(this.theJavaApplet);
  105.       }
  106.    }
  107.  
  108.    protected void onFinalize() {
  109.       for(int cnt = 0; cnt < this.numImages; ++cnt) {
  110.          if (this.imageNames[cnt] != 0) {
  111.             this.assetMan.RemoveAsset(this.imageNames[cnt]);
  112.          }
  113.       }
  114.  
  115.       for(int cnt = 0; cnt < this.numImages; ++cnt) {
  116.          if (this.imageURLs[cnt] != 0) {
  117.             this.assetMan.RemoveAsset(this.imageURLs[cnt]);
  118.          }
  119.       }
  120.  
  121.    }
  122.  
  123.    public void onInspect(CStringArray Names, CStringArray Types) {
  124.       Names.Set(ResourceBundle.getBundle("TimeBasedComp").getString("Number_of_Images"));
  125.       Types.Set("Collection");
  126.  
  127.       for(int cnt = 0; cnt < this.numImages; ++cnt) {
  128.          Names.Set(ResourceBundle.getBundle("TimeBasedComp").getString("Image") + " " + Integer.toString(cnt + 1));
  129.          Types.Set("Image");
  130.          Names.Set(ResourceBundle.getBundle("TimeBasedComp").getString("URL_for_Image") + " " + Integer.toString(cnt + 1));
  131.          Types.Set("Link");
  132.          Names.Set(ResourceBundle.getBundle("TimeBasedComp").getString("Start_Time_for_Image") + " " + Integer.toString(cnt + 1));
  133.          Types.Set("Set(" + ResourceBundle.getBundle("TimeBasedComp").getString("Start_Time_List") + ")");
  134.       }
  135.  
  136.    }
  137.  
  138.    public String onInstall(DAssetManager cam, String codebase) {
  139.       this.assetMan = cam;
  140.       return ResourceBundle.getBundle("TimeBasedComp").getString("Component_Name");
  141.    }
  142.  
  143.    public void onPublish(DAssetManager asm, int context) {
  144.       this.migrationPatch();
  145.       if (context == 1) {
  146.          for(int cnt = 0; cnt < this.numImages; ++cnt) {
  147.             String theLoc = this.assetMan.GetAssetLocation(this.imageNames[cnt], context, 0);
  148.             theLoc.replace('|', ':');
  149.             this.theJavaApplet.AddParam("Image " + Integer.toString(cnt + 1), "String", theLoc);
  150.          }
  151.       } else {
  152.          for(int cnt = 0; cnt < this.numImages; ++cnt) {
  153.             this.theJavaApplet.AddParam("Image " + Integer.toString(cnt + 1), "String", this.assetMan.GetAssetRelativeLocation(this.imageNames[cnt], context, 0));
  154.          }
  155.       }
  156.  
  157.       for(int cnt = 0; cnt < this.numImages; ++cnt) {
  158.          String theURL;
  159.          if (this.imageURLs[cnt] != 0) {
  160.             theURL = this.assetMan.GetAssetLocation(this.imageURLs[cnt], context, 1);
  161.          } else {
  162.             theURL = "";
  163.          }
  164.  
  165.          this.theJavaApplet.AddParam("URL for Image " + Integer.toString(cnt + 1), "String", theURL);
  166.          this.theJavaApplet.AddParam("target" + Integer.toString(cnt + 1), "String", this.linkTargets[cnt]);
  167.          this.theJavaApplet.AddParam("Start Time for Image " + Integer.toString(cnt + 1), "String", Integer.toString(this.imageStarts[cnt]));
  168.       }
  169.  
  170.       this.theJavaApplet.AddParam("Image Width", "String", Integer.toString(this.maxWidth));
  171.       this.theJavaApplet.AddParam("Image Height", "String", Integer.toString(this.maxHeight));
  172.       DRect thePosition = this.theJavaApplet.getObjectRect();
  173.       this.theJavaApplet.AddParam("X Position", "String", Integer.toString(thePosition.getLeft()));
  174.       this.theJavaApplet.AddParam("Y Position", "String", Integer.toString(thePosition.getTop() + 7));
  175.       DLayout layout = this.theJavaApplet.getLayout();
  176.       DSite site = layout.getSite();
  177.       DStyle style = site.getCurrentStyle();
  178.       int backgroundStyle = layout.getBackgroundStyle();
  179.       if (backgroundStyle != 0) {
  180.          if (backgroundStyle == 1) {
  181.             this.theJavaApplet.AddParam("BackgroundColor", "String", Integer.toString(layout.getBackgroundColor()));
  182.          } else if (backgroundStyle == 2) {
  183.             int backID = this.assetMan.AddAsset(layout.getBackgroundImage(), "Image", "");
  184.             String theParam = this.assetMan.GetAssetRelativeLocation(backID, context, 1);
  185.             if (context == 1) {
  186.                theParam = theParam;
  187.             }
  188.  
  189.             this.theJavaApplet.AddParam("BackgroundImage", "String", theParam);
  190.          }
  191.       } else {
  192.          backgroundStyle = style.getBackgroundStyle();
  193.          if (backgroundStyle == 1) {
  194.             this.theJavaApplet.AddParam("BackgroundColor", "String", Integer.toString(style.getBackgroundColor()));
  195.          } else if (backgroundStyle == 2) {
  196.             int backID = this.assetMan.AddAsset(style.getBackgroundImage(), "Image", "");
  197.             String theParam = this.assetMan.GetAssetRelativeLocation(backID, context, 1);
  198.             if (context == 1) {
  199.                theParam = theParam;
  200.             }
  201.  
  202.             this.theJavaApplet.AddParam("BackgroundImage", "String", theParam);
  203.          }
  204.       }
  205.  
  206.    }
  207.  
  208.    public void onUnInstall(DAssetManager cam) {
  209.    }
  210.  
  211.    public String PropertyListener(String Event, String Value, int Get, int propIndex, IDInspector insp) {
  212.       this.migrationPatch();
  213.       if (Get == 1) {
  214.          if (Event.compareTo(ResourceBundle.getBundle("TimeBasedComp").getString("Number_of_Images")) == 0) {
  215.             return Integer.toString(this.numImages);
  216.          }
  217.  
  218.          for(int cnt = 0; cnt < this.numImages; ++cnt) {
  219.             if (Event.compareTo(ResourceBundle.getBundle("TimeBasedComp").getString("Image") + " " + Integer.toString(cnt + 1)) == 0) {
  220.                return Integer.toString(this.imageNames[cnt]);
  221.             }
  222.  
  223.             if (Event.compareTo(ResourceBundle.getBundle("TimeBasedComp").getString("URL_for_Image") + " " + Integer.toString(cnt + 1)) == 0) {
  224.                return Integer.toString(this.imageURLs[cnt]);
  225.             }
  226.  
  227.             if (Event.compareTo(ResourceBundle.getBundle("TimeBasedComp").getString("Start_Time_for_Image") + " " + Integer.toString(cnt + 1)) == 0) {
  228.                return Integer.toString(this.imageStarts[cnt]);
  229.             }
  230.          }
  231.       } else if (Event.compareTo(ResourceBundle.getBundle("TimeBasedComp").getString("Number_of_Images")) == 0) {
  232.          int newNumImages = Integer.parseInt(Value, 10);
  233.          if (newNumImages < 1) {
  234.             return "";
  235.          }
  236.  
  237.          if (newNumImages > 24) {
  238.             newNumImages = 24;
  239.          }
  240.  
  241.          for(int i = 0; i < newNumImages; ++i) {
  242.             if (this.imageNames[i] != 0) {
  243.                String theImageFile = this.assetMan.GetAssetLocation(this.imageNames[i], 1, 1);
  244.                this.theJavaApplet.setImageFile(theImageFile);
  245.                break;
  246.             }
  247.          }
  248.  
  249.          if (newNumImages < this.numImages) {
  250.             for(int i = newNumImages; i < this.numImages; ++i) {
  251.                this.imageURLs[i] = 0;
  252.             }
  253.  
  254.             DImage imageSizer = new DImage();
  255.             this.maxHeight = this.maxWidth = 0;
  256.  
  257.             for(int iter = 0; iter < newNumImages; ++iter) {
  258.                String theImageFile = this.assetMan.GetAssetLocation(this.imageNames[iter], 1, 1);
  259.                imageSizer.setImageFile(theImageFile);
  260.                DSize currentImageSize = imageSizer.getSize();
  261.                if (currentImageSize.getHeight() > this.maxHeight) {
  262.                   this.maxHeight = currentImageSize.getHeight();
  263.                }
  264.  
  265.                if (currentImageSize.getWidth() > this.maxWidth) {
  266.                   this.maxWidth = currentImageSize.getWidth();
  267.                }
  268.             }
  269.  
  270.             this.theJavaApplet.SetSize(this.maxWidth, this.maxHeight);
  271.          }
  272.  
  273.          while(newNumImages < this.numImages) {
  274.             this.assetMan.RemoveAsset(this.imageNames[--this.numImages]);
  275.          }
  276.  
  277.          this.numImages = newNumImages;
  278.          this.theJavaApplet.AddParam("Number of Images", "String", Integer.toString(this.numImages));
  279.       } else {
  280.          for(int cnt = 0; cnt < this.numImages; ++cnt) {
  281.             if (Event.compareTo(ResourceBundle.getBundle("TimeBasedComp").getString("Image") + " " + Integer.toString(cnt + 1)) == 0) {
  282.                if (this.imageNames[cnt] != 0) {
  283.                   this.assetMan.RemoveAsset(this.imageNames[cnt]);
  284.                }
  285.  
  286.                this.imageNames[cnt] = Integer.parseInt(Value, 10);
  287.                String theImageFile = this.assetMan.GetAssetLocation(this.imageNames[cnt], 1, 1);
  288.                this.theJavaApplet.setImageFile(theImageFile);
  289.                DImage imageSizer = new DImage();
  290.                this.maxHeight = this.maxWidth = 0;
  291.  
  292.                for(int iter = 0; iter < this.numImages; ++iter) {
  293.                   theImageFile = this.assetMan.GetAssetLocation(this.imageNames[iter], 1, 1);
  294.                   imageSizer.setImageFile(theImageFile);
  295.                   DSize currentImageSize = imageSizer.getSize();
  296.                   if (currentImageSize.getHeight() > this.maxHeight) {
  297.                      this.maxHeight = currentImageSize.getHeight();
  298.                   }
  299.  
  300.                   if (currentImageSize.getWidth() > this.maxWidth) {
  301.                      this.maxWidth = currentImageSize.getWidth();
  302.                   }
  303.                }
  304.  
  305.                this.theJavaApplet.SetSize(this.maxWidth, this.maxHeight);
  306.             }
  307.  
  308.             if (Event.compareTo(ResourceBundle.getBundle("TimeBasedComp").getString("URL_for_Image") + " " + Integer.toString(cnt + 1)) == 0) {
  309.                this.imageURLs[cnt] = Integer.parseInt(Value, 10);
  310.                if (this.assetMan.LinkHasFrames(this.imageURLs[cnt]) != 0) {
  311.                   this.linkTargets[cnt] = this.assetMan.GetTargetFromLink(this.imageURLs[cnt]);
  312.                } else {
  313.                   this.linkTargets[cnt] = "";
  314.                }
  315.             }
  316.  
  317.             if (Event.compareTo(ResourceBundle.getBundle("TimeBasedComp").getString("Start_Time_for_Image") + " " + Integer.toString(cnt + 1)) == 0) {
  318.                this.imageStarts[cnt] = Integer.parseInt(Value, 10);
  319.                if (this.imageStarts[cnt] > 23) {
  320.                   this.imageStarts[cnt] = 23;
  321.                } else if (this.imageStarts[cnt] < 0) {
  322.                   this.imageStarts[cnt] = 0;
  323.                }
  324.             }
  325.          }
  326.       }
  327.  
  328.       return "";
  329.    }
  330. }
  331.